#ifndef FPLAYER_THREADMANAGER_H
#define FPLAYER_THREADMANAGER_H


#include "HandlerThread.h"

/**
 * author: x-fan
 * date: 2024/1/11
 * desc: 管理线程的创建、销毁
 */
class ThreadManager : public HandlerThread {

private:
  static ThreadManager *_Instance;

  ThreadManager() = default;

public:
  ThreadManager(const ThreadManager &) = delete;

  const ThreadManager *operator=(const ThreadManager &) = delete;

  //单例对象
  static ThreadManager *Instance();

  //销毁单例对象
  static void Destroy();

  /**
   * 创建并启动线程
   * @param pThread Handler线程对象
   * @param param 携带参数
   * @return true:启动成功
   */
  bool createThread(HandlerThread *pThread, void *param = nullptr);

  /**
   * 销毁线程
   * @param pThread Handler线程对象
   */
  void destroyThread(HandlerThread *pThread);

  void handleMessage(Message *pMsg) override;

  const char *getClassName() override;

  void toString() override;

};


#endif //FPLAYER_THREADMANAGER_H
